﻿using System;
using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using System.Diagnostics.CodeAnalysis;
using iTeamyou.LTS.UI.Models;
using iTeamyou.LTS.Core.Services;

namespace iTeamyou.LTS.UI.Shared.Components.Mobile
{
    public partial class ProductMobileSearch
    {
        /// <summary>
        /// 
        /// </summary>
        [Parameter]
        [NotNull]
        public ProductSearchModel? Value { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Parameter]
        public EventCallback<ProductSearchModel> ValueChanged { get; set; }

        public ProductService? ProductService { get; set; }
        public List<SelectedItem>? ProductBrandList { get; set; }
        public List<SelectedItem>? ProductCategoryList { get; set; }
        public List<SelectedItem> LicenseCountList { get; set; }

        public ProductMobileSearch()
        {
            var sharedService = new SharedService();
            var ProductService = new ProductService(sharedService.GetConnectionString("MainDB"));

            //var categories = ProductService.GetProductCategories();
            var categories = ProductService.GetProductDepartments();
            if (categories != null && categories.Any())
            {
                ProductCategoryList = new List<SelectedItem>
                {
                    new SelectedItem() { Text = "", Value = "" }
                };
                foreach (var category in categories)
                {
                    ProductCategoryList.Add(new SelectedItem() { Text = category.Description, Value = category.Id });
                }
            }

            var brands = ProductService.GetProductBrands();
            if (brands != null && brands.Any())
            {
                ProductBrandList = new List<SelectedItem>();
                foreach (var brand in brands)
                {
                    if (string.IsNullOrEmpty(brand))
                        ProductBrandList.Add(new SelectedItem() { Text = "", Value = "" });
                    else
                        ProductBrandList.Add(new SelectedItem() { Text = brand, Value = brand });
                }
            }

            LicenseCountList = new List<SelectedItem>
            {
                new SelectedItem() { Text = "请选择有无证照", Value = string.Empty },
                new SelectedItem() { Text = "有证照", Value = "1" },
                new SelectedItem() { Text = "无证照", Value = "0" },
                new SelectedItem() { Text = "全部", Value = "9" }
            };
        }
    }
}

